// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import App from './App'
import routes from './router/index'
import axios from 'axios'
import Vuex from 'vuex'
import { ToastPlugin, LoadingPlugin, Previewer } from 'vux'
import qs from 'qs'

Vue.use(VueRouter)
Vue.use(Vuex)
Vue.prototype.$axios = axios // ajax封装类
Vue.use(ToastPlugin)
Vue.use(LoadingPlugin)
Vue.use(Previewer)
Vue.prototype.$qs = qs // ajax请求参数格式化类

const router = new VueRouter({
  routes
})

FastClick.attach(document.body)

Vue.config.productionTip = false

// vuex存储定义
const store = new Vuex.Store({})

store.registerModule('vux', {
  state: {
    isLoading: false, // 是否显示加载
    isTitle: '办事',  // 头部导航文字
    orgCode: '',  // 挂号 医疗机构ID
    deptCode: ''  // 挂号 科室ID
  },
  mutations: {
    updateLoadingStatus (state, payload) {
      state.isLoading = payload.isLoading
    },
    updataTitleStatus (state, title) {
      state.isTitle = title
    },
    updataOrgCodeStatus (state, orgCode) {
      state.orgCode = orgCode
    },
    updataDeptIdStatus (state, deptCode) {
      state.deptCode = deptCode
    }
  }
})

router.beforeEach(function (to, from, next) {
  store.commit('updateLoadingStatus', {isLoading: true})
  next()
})

router.afterEach(function (to) {
  store.commit('updateLoadingStatus', {isLoading: false})
})

/* eslint-disable no-new */
new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app-box')
